<template>
	<publicPage>
		<!-- 列表 -->
		<scroll-view
			v-if="list && list.length"
			scroll-y
			style="height: 100%"
			@scrolltolower="scrolltolower"
			refresher-enabled
			:refresher-triggered="refresherTriggered"
			@refresherrefresh="refresherrefresh"
		>
			<view
				v-for="(item, index) in list"
				:key="index"
				class="forBox"
				@click="loginGo(`/pagesC/expHome/index?expertId=${item.id}&hideImConsult=true`)"
			>
				<InfoCard :item="item" />
				<BtnList :item="item" :showImConsult="false" />
			</view>
		</scroll-view>

		<!-- 缺省页 -->
		<view class="defaultPage disFlxCC" v-if="!list.length && listLoad">
			<view>
				<u-image
					src="https://onelive.obs.cn-south-1.myhuaweicloud.com/uniapp/static/image220701%287%29.png"
					width="166rpx"
					height="166rpx"
				></u-image>
			</view>
			<view class="pt-8 pb-47 color9">该团队内暂无专家</view>
		</view>
	</publicPage>
</template>

<script>
import orderApi from "@/api/order.js";
import InfoCard from "@/components/infoCard.vue";
import BtnList from "@/components/btnList.vue";

export default {
  components: {
		InfoCard,
		BtnList,
	},
	data() {
		return {
			list: [],
			listLoad: false, // 加载是否完成
			getParams: {
				pageNum: 1,
				pageSize: 10,
				total: 0,
        teamId: "",
				userType: "0", // 0专家 1用户
			},
			refresherTriggered: false,
		};
	},
	onLoad(options) {
    this.getParams.teamId = options.teamId;
		this.getList();
	},
	methods: {
		// 获取专家列表
		async getList() {
			try {
				const { data, total } = await orderApi.teamExpList(this.getParams);
				this.list = this.getParams.pageNum === 1 ? data : [...this.list, ...data];
				this.getParams.total = total;
				this.listLoad = true;
			} catch (error) {
				this.listLoad = true;
			}
		},
    scrolltolower() {
			if (this.list.length !== this.getParams.total) {
				// u-view内部节流函数
				uni.$u.throttle(() => {
					this.getParams.pageNum++;
					this.getList();
					console.log(this.getParams.pageNum, "滚动加载");
				}, 2000);
			} else {
				console.log("没有更多了");
			}
		},
    async refresherrefresh() {
			this.refresherTriggered = true;
			this.$data.getParams.pageNum = this.$options.data().getParams.pageNum;
			this.$data.getParams.total = this.$options.data().getParams.total;
			await this.getList();
			console.log(this.getParams.pageNum, "下拉刷新");
			setTimeout(() => {
				this.refresherTriggered = false;
			}, 1000);
		},
	},
};
</script>

<style lang="scss" scoped>
.defaultPage {
	height: 100%;
}
.forBox {
	margin-top: 30rpx;
	margin-left: 30rpx;
	margin-right: 30rpx;
	border-radius: 20rpx;
	overflow: hidden;
	background-color: #ffffff;
}
</style>
